home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / strategy / xsok-1.000 / xsok-1 / xsok-1.01 / src / score.c < prev    next >
C/C++ Source or Header  |  1994-11-24  |  2KB  |  58 lines

  1. /*****************************************************************************/
  2. /*                                         */
  3. /*                                         */
  4. /*    Xsok version 1.00 -- module score.c                     */
  5. /*                                         */
  6. /*    Score computation and checking for finished levels.             */
  7. /*    Written by Michael Bischoff (mbi@mo.math.nat.tu-bs.de)             */
  8. /*    November-1994                                 */
  9. /*    see COPYRIGHT.xsok for Copyright details                 */
  10. /*                                         */
  11. /*                                         */
  12. /*****************************************************************************/
  13. #ifndef _POSIX_SOURCE
  14. #define _POSIX_SOURCE
  15. #endif
  16. #include "xsok.h"
  17.  
  18. void change_rules(const char *type) {
  19.     game.type = type;
  20.     game.level = 0;
  21.     ParseDefinitionFile();
  22. }
  23.  
  24. int compute_score(void) {
  25.     int x, y;
  26.     int retval = 1;
  27.     game.score = 0;
  28.     for (x = 1; x < game.numcols; ++x)
  29.     for (y = 1; y < game.numrows; ++y) {
  30.         int c;
  31.         c = map[y][x]->effect;
  32.         if (c == E_EXIT) {
  33.         if (game.x != x || game.y != y)
  34.             retval = 0;    /* EXIT field with no player on it */
  35.         else
  36.             game.score += obj[y][x]->score;
  37.         }
  38.         if (c == E_DEST)
  39.         if (!obj[y][x] || !(obj[y][x]->mask & ~1))
  40.             retval = 0;    /* player doesn't score! */
  41.         else
  42.             game.score += obj[y][x]->score;
  43.     }
  44.     if (retval && !objects->score)
  45.     game.score += 10000;    /* finished-score if no special EXIT square */
  46.     game.score -= movecost * game.n_moves + pushcost * game.n_pushes;
  47.     if (game.score < 0)
  48.     game.score = 0;
  49.     return retval;
  50. }
  51.  
  52. int finished(void) {
  53.     if (!compute_score())
  54.     return game.finished = 0;
  55.     cmd_ShowScore();
  56.     return game.finished = 1;
  57. }
  58.